package com.lu.test.designpattern.listenermode.target1;

import com.lu.test.designpattern.listenermode.event.WeekendEvent;
import com.lu.test.designpattern.listenermode.listenter.WeekendListener;

import java.util.ArrayList;
import java.util.List;

public abstract class AbstractEventMulticaster {
	public List<WeekendListener> listeners ;

	public AbstractEventMulticaster(List<WeekendListener> listeners){
		this.listeners = new ArrayList<>(listeners);
	}

	public void multicaster(WeekendEvent event){
		doStart();
		listeners.forEach(l -> l.onEvent(event));
		doEnd();
	}

	public void addListener(WeekendListener listener){
		listeners.add(listener);
	}

	public void removeListener(WeekendListener listener){
		listeners.remove(listener);
	}

	abstract public void doStart();

	abstract public void doEnd();
}
